<?php
namespace app\dlc\controller;
use app\common\model\Form;
use app\common\model\FormItem;
use app\common\model\Site;
use think\Db;

class FormListItemController extends CommonController
{

    public function _initialize(){
        parent::_initialize();

    }
    public function index()
    {

        $this->bread_ininput('表单管理-列表管理-基本配置');
        $this->title = '基本配置';
        $this->headBotton('','back','返回','/dlc/FormList/index');
        $this->headBotton('','add','添加',CONTROLLER_URL.'_edit_ajax',2);
        $this->headSearch('','name','字段名称','1');
        $this->headSearch('','form_id','所属识别名',2,Db::name('form')->column('id,index_name'));
        $this->listBotton('','edit','编辑',CONTROLLER_URL.'_edit_ajax',2,'','','','',['onClick' => 'openNewWindows']);
        $this->listBotton('','delete','删除',CONTROLLER_URL.'_del');
        $this->loading();
        $map = $this->map;
        self::$page = '1,30';
        self::$psize = '30';
        $data = model($this->className)->where($map)->order('type,sort asc')->page(self::$page)->select();
        foreach ($data as $key => $value) {
            if (in_array($value['type'],[2,4])){
                $data[$key]['url'] =  '无';
            }
            $data[$key]['sort'] = $this->listInput('',$value['id'],'sort',$value['sort']);
            $data[$key]['name'] = $this->listInput('',$value['id'],'name',$value['name']);
        }
        $count = Db::name($this->className)->where($map)->count();
        $this->getPage($count, self::$psize, 'App-loader', $this->title, 'App-search');
        $this->assign('data',$data);
        $list = ['id'=>'ID','table'=>'表名','typeText'=>'类型','key'=>'字段或者自定义英文名','name'=>'中文名','url'=>'url','role'=>'权限','sort'=>'排序（从小到大）','ctime'=>'创建时间','sys'=>'操作'];
        $this->assign('list',$list);
        echo $this->fetch('common/index');
    }

    public function _edit_ajax($updata = false, $add = false, $noRepeat = false, $funName = false)
    {

        $post = input('post.');
        $id = input('id')?:'';
        if (empty($id)){

            $res = Db::name(CONTROLLER_NAME)->insert($post);
            if ($res) admin_return(1,'添加成功');
        }
        parent::_edit_ajax($updata, $add, $noRepeat, $funName); // TODO: Change the autogenerated stub
    }


}